package org.example.buysystem.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.buysystem.common.Result;
import org.example.buysystem.entity.Icon;
import org.example.buysystem.service.IconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/icon")
@CrossOrigin
@Api(value = "图标",tags = {"图标模块"})
public class IconController {

    @Autowired
    private IconService iconService;

    @GetMapping
    @ApiOperation(value = "获取图标")
    public Result getIcon(){
        List<Icon> list= iconService.getIconCatehoryMapList();
        return Result.success(list);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据图标id进行查询")
    public Result getIconById(@PathVariable Long id){
        return Result.success(iconService.getById(id));
    }

    @PostMapping
    @ApiOperation("保存图标")
    public Result save(@RequestBody Icon icon){
        iconService.save(icon);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("更新图标")
    public Result update(@RequestBody Icon icon){
        iconService.updateById(icon);
        return Result.success();
    }

    @GetMapping("/delete")
    @ApiOperation("根据id进行删除")
    public Map<String,Object> deleteById(@RequestParam Long id){
        return iconService.deleteById(id);


    }



}
